home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Sessions / Completions / Completions Source / Files / FileInStream.cp < prev    next >
Encoding:
Text File  |  1998-06-17  |  1.9 KB  |  115 lines  |  [TEXT/CWIE]

  1. // FileInStream.cp
  2.  
  3. #ifndef FileInStream_h
  4. #include "FileInStream.h"
  5. #endif
  6. #ifndef Data_h
  7. #include "Data.h"
  8. #endif
  9. #ifndef FileReadingPath_h
  10. #include "FileReadingPath.h"
  11. #endif
  12. #ifndef __DEVICES__
  13. #include <Devices.h>
  14. #endif
  15. #ifndef __ERRORS__
  16. #include <Errors.h>
  17. #endif
  18.  
  19. FileInStream::FileInStream()
  20.   {
  21.     ioParam.ioPosMode = fsFromStart;
  22.   }
  23.  
  24. Task *FileInStream::NonblockingRead( Data buffer )
  25.   {
  26.     return BlockingRead( buffer );
  27.   }
  28.  
  29. Task *FileInStream::BlockingRead( Data buffer )
  30.   {
  31.     Assert( !Running() );
  32.     ioParam.ioBuffer = reinterpret_cast<Ptr>( buffer.Start() );
  33.     ioParam.ioReqCount = buffer.Length();
  34.  
  35.     return this;
  36.   }
  37.  
  38. void FileInStream::Launch()
  39.   {
  40.     Assert( !Running() );
  41.     PBReadAsync( this );
  42.   }
  43.  
  44. void FileInStream::Kill()
  45.   {
  46.   }
  47.  
  48. void FileInStream::AtCompletion()
  49.   {
  50.     Assert( !Running() );
  51.  
  52.     ReportRead( ioParam.ioActCount );
  53.     
  54.     if ( ioParam.ioResult != noErr )
  55.       {
  56.         if ( ioParam.ioResult == eofErr )
  57.             ReportEnd();
  58.          else
  59.             ReportFailure();
  60.       }
  61.   }
  62.         
  63. void FileInStream::SetFile( const FileReadingPath& path,
  64.                                      uint32 position )
  65.   {
  66.     Assert( !Running() );
  67.     Assert( path.IsOpen() );
  68.     
  69.     ioParam.ioRefNum = path.RefNum();
  70.     ioParam.ioPosOffset = position;
  71.     Reset();
  72.   }
  73.  
  74. void FileInStream::ClearFile()
  75.   {
  76.     Assert( !Running() );
  77.     ioParam.ioRefNum = 0;
  78.     Reset();
  79.   }
  80.  
  81. uint32 FileInStream::Position() const
  82.   {
  83.     Assert( !Running() );
  84.     Assert( HasFile() );
  85.     return ioParam.ioPosOffset;
  86.   }
  87.         
  88. void FileInStream::SetPosition( uint32 p )
  89.   {
  90.     Assert( !Running() );
  91.     Assert( HasFile() );
  92.     ioParam.ioPosOffset = p;
  93.     Reset();
  94.   }
  95.         
  96. void FileInStream::SuggestCaching()
  97.   {
  98.     Assert( !Running() );
  99.     ioParam.ioPosMode |= cacheBit;
  100.     ioParam.ioPosMode &= ~noCacheBit;
  101.   }
  102.         
  103. void FileInStream::SuggestNoCaching()
  104.   {
  105.     Assert( !Running() );
  106.     ioParam.ioPosMode |= noCacheBit;
  107.     ioParam.ioPosMode &= ~cacheBit;
  108.   }
  109.         
  110. void FileInStream::ClearCachingSuggestion()
  111.   {
  112.     Assert( !Running() );
  113.     ioParam.ioPosMode &= ~( noCacheBit | cacheBit );
  114.   }
  115.